<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>测试页面</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/node_modules/LobsterUIFrame/weui/css/weui.css" />
    <link rel="stylesheet" href="/node_modules/LobsterUIFrame/weui/css/weuix.css" />
    <script src="/node_modules/LobsterUIFrame/weui/js/zepto.min.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/zepto.weui.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/swipe.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/macy.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/php.js"></script>
    <script src="/lobstersdk/lobster.js"></script>
</head>


<body>
    <div class="weui-msg" id="s1">
        <div>测试数据</div>
        <div>{
            SubMchId:'20220505085609644323',//
            BusinessOrderNo:'123',
            OrderType:1,//业务类型 1预约挂号 2自助缴费
            PayType:1,//默认1 微信支付
            Price:4,单位分
            Body:'预约挂号',//商品描述
            Memo:'备注'//可以不填
            ,tradelist:[{UserId:"1624064245",Amount:4,TradeMethod:0,FinancialBalance:1}
            ,{UserId:"6117",Amount:4,TradeMethod:0,FinancialBalance:1}]
            }</div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" id="topay" class="weui-btn weui-btn_primary">预下单</a>
            </p>
        </div>
        <div>退款测试数据</div>
        <div>
            {
            SubMchId: '20220505085609644323',//
            BusinessOrderNo: '123',
            OrderType: 1,//业务类型 1预约挂号 2自助缴费
            PayType: 1,//默认1 微信支付
            Price: 4, //单位分
            Body: '用户退款',//商品描述
            Memo: '备注'//可以不填
            }
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" id="refund" class="weui-btn weui-btn_primary">交易退款</a>

            </p>
        </div>
    </div>
</body>
<script>
    lobsterh5.main({
        data: {

        },
        //初始化页面
        pageload: function () {
            var self = this;
            $("#topay").click(function () {
                lobsterh5.CALLOUTSERVICE("wallet.wallet.pretransaction", {
                    SubMchId: '20220505085609644323',//
                    BusinessOrderNo: self.generateTimeReqestNumber(),
                    OrderType: 1,//业务类型 1预约挂号 2自助缴费 3商城购买
                    PayType: 1,//默认1 微信支付
                    PayScene: 1,//1 h5 2小程序 3app
                    Price: 1, //单位分
                    Body: '商品购买',//商品描述
                    Memo: '备注'//可以不填
                    , tradelist: JSON.stringify([{ UserId:localStorage.getItem("userId"), Amount: 1, TradeMethod: 0, FinancialBalance: 2 }
                        , { UserId: "6117", Amount: 1, TradeMethod: 0, FinancialBalance: 1 }])//FinancialBalance 1收入 2支出 UserId=6117代表管理员
                }).then(res => {
                    location = res.payredirecturl;
                }).catch(res => {
                    $.toast(res.msg, 'forbidden');
                });
            })
            $("#refund").click(function () {
                lobsterh5.CALLOUTSERVICE("wallet.wallet.transactionrefund", {
                    SubMchId: '20220505085609644323',
                    BusinessOrderNo: "20220623142511460295",
                    BusinessRefundNo: "R20220623142853270787",
                    PayType: 1,//默认1 微信支付
                    RefundRealFee: 1, //单位分
                    RefundDesc: '用户退款',//商品描述 
                }).then(res => {
                    $.toast("退款成功");
                }).catch(res => {
                    $.toast(res.msg, 'forbidden');
                });
            })
        },
        generateTimeReqestNumber: function () {
            var self = this;
            var date = new Date();
            return date.getFullYear().toString() + self.pad2(date.getMonth() + 1) + self.pad2(date.getDate()) + self.pad2(date.getHours()) + self.pad2(date.getMinutes()) + self.pad2(date.getSeconds()) + Math.random().toFixed(6).slice(-6);
        },

        pad2: function (n) { return n < 10 ? '0' + n : n + '' },
    }) 
</script>

</html>